# -*-coding:utf-8 -*-
"""
专题报表-沪深股票-机构持股-机构持股汇总表（按品种）
"""
from EmQuantAPI import *
import common.mainApi as mp
import common.handler_date_time as hd_dt
import common.handler_ctr_result as hd_cr
import common.dataFrame as df
import common.sql as db
import common.mainApi as ma
import config.base_info as bs

base_type = "ctr"
base_target = "target"
base_index = "InstHolderTypeInfo"

info_ = bs.INDEX_INFO.get(base_type).get(base_target).get(base_index)  # ->dict
param_code = info_.get("return_data")  # ->list
param_ = ",".join(param_code)
option_ = "OrgType=0,reportDate="


def mainGetInstHolderTypeInfo(reportdate="2020-12-31",predictyear="2020"):
   
    data = c.ctr(base_index, param_, option_+reportdate+",PredictYear="+predictyear)

    return data

if __name__ == "__main__":
    mp.login()
    temp_=[
        ["1999-12-31","1999"],
        ["1999-09-30","1999"],
        ["1999-06-30","1999"],
        ["1999-03-31","1999"],

        ["1998-12-31","1998"],
        ["1998-09-30","1998"],
        ["1998-06-30","1998"],
        ["1998-03-31","1998"],

        ["1997-12-31","1997"],
        ["1997-09-30","1997"],
        ["1997-06-30","1997"],
        ["1997-03-31","1997"],

        ["1996-12-31","1996"],
        ["1996-09-30","1996"],
        ["1996-06-30","1996"],
        ["1996-03-31","1996"],

        ["1995-12-31","1995"],
        ["1995-09-30","1995"],
        ["1995-06-30","1995"],
        ["1995-03-31","1995"],

        ["1994-12-31","1994"],
        ["1994-09-30","1994"],
        ["1994-06-30","1994"],
        ["1994-03-31","1994"],

        ["1993-12-31","1993"],
        ["1993-09-30","1993"],
        ["1993-06-30","1993"],
        ["1993-03-31","1993"],

        ["1992-12-31","1992"],
        ["1992-09-30","1992"],
        ["1992-06-30","1992"],
        ["1992-03-31","1992"],

        ["1991-12-31","1991"],
        ["1991-09-30","1991"],
        ["1991-06-30","1991"],
        ["1991-03-31","1991"],
    ]
    for k in temp_:

        data=mainGetInstHolderTypeInfo(reportdate=k[0],predictyear=k[1])
        hd_cr.ctr_result_handler(data_res=data,index_=base_index)
    mp.stop()
    db.dbcon_dispose() #close-db



